package com.ch.movie.repository

import com.ch.common.net.RetrofitManager
import com.ch.common.net.RetrofitManager.await
import com.ch.common.net.RetrofitManager.launcherNetApi
import com.ch.movie.netApi.WebServiceApi
import kotlinx.coroutines.Dispatchers

object MovieRepository {
    private var mWebServiceApi: WebServiceApi =
        RetrofitManager.createServiceApi(WebServiceApi::class.java)


    fun getMovieData() = launcherNetApi(Dispatchers.IO) {
        val bean = mWebServiceApi.getMovieData().await()
        if (bean.ret == 0) {
            Result.success(bean.data)
        } else {
            Result.failure(RuntimeException(""))
        }
    }
}